package com.xbongbong.crm.service.condition;

import com.xbongbong.paas.domain.entity.ext.ConditionsEntityExt;
import com.xbongbong.paas.enums.ConditionEnum;
import com.xbongbong.parent.abstracts.AbstractConditionService;
import com.xbongbong.parent.pojo.list.ConditionListPojo;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.ContractEnum;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * @author 吴峰
 * @date 2022/06/15 16:38
 */
@Service("contractConditionServiceImpl")
public class ContractConditionServiceImpl extends AbstractConditionService {

    @Override
    public List<Integer> businessType() {
        return Arrays.asList(XbbRefTypeEnum.CONTRACT.getCode(), XbbRefTypeEnum.ORDER.getCode());
    }

    @Override
    public List<ConditionsEntityExt> packageConditionBySubBusinessType(ConditionListPojo conditionListPojo) {
        List<ConditionsEntityExt> conditionList = new ArrayList<>();
        ConditionsEntityExt conditionsEntityExt = new ConditionsEntityExt();
        conditionsEntityExt.setAttr(ContractEnum.IS_RED.getAttr());
        conditionsEntityExt.setFieldType(ContractEnum.IS_RED.getFieldType());
        conditionsEntityExt.setSymbol(ConditionEnum.EQUAL.getSymbol());
        conditionsEntityExt.setValue(Collections.singletonList(0));
        conditionList.add(conditionsEntityExt);
        Integer statusFilter = conditionListPojo.getStatusFilter();
        if (!(Objects.isNull(statusFilter) || statusFilter == 0)){
            ConditionsEntityExt statusFilterEntityExt = new ConditionsEntityExt();
            statusFilterEntityExt.setAttr(ContractEnum.ARCHIVED.getAttr());
            statusFilterEntityExt.setFieldType(ContractEnum.ARCHIVED.getFieldType());
            statusFilterEntityExt.setSymbol(ConditionEnum.EQUAL.getSymbol());
            statusFilterEntityExt.setValue(Collections.singletonList(statusFilter));
            conditionList.add(statusFilterEntityExt);
        }
        return conditionList;
    }
}
